﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using InfoSoftGlobal;

public partial class sysadmin_CountManager_FCFProject : PowerCreator.LMS.Web.Base.BasePage
{
    PowerCreator.LMS.Web.Project.Project opProject = new PowerCreator.LMS.Web.Project.Project();
    PowerCreator.LMS.ViewQuery.ViewQuery opViewQuery = new PowerCreator.LMS.ViewQuery.ViewQuery();
    PowerCreator.LMS.Web.Project.NewProjectPlan opProjectPlan = new PowerCreator.LMS.Web.Project.NewProjectPlan();
    
    string _cmd1 = "select count(*) from TStudentPassProjectLog where FKSpplogTrainproID={0}";   //查询总人数
    string _cmd2 = "select count(*) from TStudentPassProjectLog where FKSpplogTrainproID={0} and SpplogState=16";  //通过人数
    string _cmd3 = "select count(*) from TStudentPassProjectLog where FKSpplogTrainproID={0} and SpplogState=17";  //未通过人数

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string search = GetSearch();
            BinderPager(search);
            BinderRPT(search, 1);
        }
    }

    #region 绑定统计图信息
    private void BinderPic()
    { 
        
    }
    #endregion

    private string GetSearch()
    {
        return "";
    }
    private void BinderPager(string search)
    {
        AspNetPager1.PageSize = LMSPageSize;
        AspNetPager1.RecordCount = opProject.QueryTrainProjectCount(search);
    }

    private void BinderRPT(string search,int pageIndex)
    {
        DataTable dt = opProject.QueryTrainProject(search,LMSPageSize,pageIndex);
        dt.Columns.Add("ProjectStudentCount1");
        dt.Columns.Add("ProjectStudentCountYes1");
        dt.Columns.Add("ProjectStudentCountNo1");

        string cmd1, cmd2, cmd3;

        for (int i = 0; i < dt.Rows.Count; i++)
        {
            cmd1 = string.Format(_cmd1, dt.Rows[i]["TrainproID"]);
            cmd2 = string.Format(_cmd2, dt.Rows[i]["TrainproID"]);
            cmd3 = string.Format(_cmd3, dt.Rows[i]["TrainproID"]);
            dt.Rows[i]["ProjectStudentCount1"] = opViewQuery.Query(cmd1, 1, 1).Rows[0][0];
            dt.Rows[i]["ProjectStudentCountYes1"] = opViewQuery.Query(cmd2, 1, 1).Rows[0][0];
            dt.Rows[i]["ProjectStudentCountNo1"] = opViewQuery.Query(cmd3, 1, 1).Rows[0][0];

            if (string.IsNullOrEmpty(dt.Rows[i]["ProjectStudentCount1"].ToString()))
            {
                dt.Rows[i]["ProjectStudentCount1"] = "0";
            }
            if (string.IsNullOrEmpty(dt.Rows[i]["ProjectStudentCountYes1"].ToString()))
            {
                dt.Rows[i]["ProjectStudentCountYes1"] = "0";
            }
            if (string.IsNullOrEmpty(dt.Rows[i]["ProjectStudentCountNo1"].ToString()))
            {
                dt.Rows[i]["ProjectStudentCountNo1"] = "0";
            }
            //if (i != 0)
            //    dt.Rows[i].Delete();
        }
        rpt_Project.DataSource = dt;
        rpt_Project.DataBind();

        //图表部分
        rpt_Pic.DataSource = dt;
        rpt_Pic.DataBind();
        for (int i = 0; i < rpt_Pic.Items.Count; i++)
        {
            Label l1 = (Label)rpt_Pic.Items[i].FindControl("Label1");
            Label l2 = (Label)rpt_Pic.Items[i].FindControl("Label2");
            Label l3 = (Label)rpt_Pic.Items[i].FindControl("Label3");
            Label l4 = (Label)rpt_Pic.Items[i].FindControl("Label4");
            Literal ll1 = (Literal)rpt_Pic.Items[i].FindControl("Literal1");

            string strXML;
            strXML = "<graph caption='" + l4.Text + "' subCaption='Bug yang' decimalPrecision='0' showNames='1'  numberSuffix='人'  pieSliceDepth='30' formatNumberScale='0' font='宋体' fontSize='18'>";
            strXML += "<set name='总人数' value='" + l1.Text + "' />";
          //  strXML += "<set name='己完成数' value='" + l2.Text + "' />";
            strXML += "<set name='未完成数' value='" + l3.Text + "' />";
            strXML += "</graph>";
            ll1.Text = FusionCharts.RenderChart(PowerCreator.LMS.Common.Utils.WebUtils.WebRoot + "/FusionCharts30/Pie2D.swf", "", strXML, "FactorySum"+i.ToString(), "650", "450", false, false);
        }
    }

    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        string search = GetSearch();
        BinderRPT(search, AspNetPager1.CurrentPageIndex);
    }
    protected void rpt_Project_ItemCommand(object source, RepeaterCommandEventArgs e)
    {

    }
}